<template>
  <!-- 判断是否需要获取手机号并且未登录 -->
  <button
    v-if="accountStore.needGetPhone && !accountStore.token"
    class="login-button"
    open-type="getPhoneNumber"
    @getphonenumber="loginHandle"
    :style="styleProps"
  />
  <!-- 判断未登录，并且已经绑定房源 -->
  <button v-else-if="!accountStore.token" class="login-button" :style="styleProps" @click="loginHandle" />
  <!-- 判断已登录， 并且未绑定房源 -->
  <!-- <button
    v-else-if="accountStore.token && !accountStore.userInfo.roomId"
    class="login-button"
    :style="styleProps"
    @click="toRoomListHandle"
  /> -->
</template>

<script setup lang="ts">
import { showModal } from '@/utils/message'
import { useAccountStore } from '@/store/modules/account'

const accountStore = useAccountStore()

const props = withDefaults(
  defineProps<{
    styleProps?: any
  }>(),
  {
    styleProps: { top: 0 }
  }
)

const loginHandle = e => {
  console.log('loginHandle', 'code', e.detail.code, 'encryptedData', e.detail.encryptedData, 'iv', e.detail.iv)
  const encryptedData = e.detail.encryptedData
  const iv = e.detail.iv
  accountStore.loginAction({
    encryptedData,
    iv
  })
}

const toRoomListHandle = () => {
  showModal({
    title: '提示',
    content: '请绑定房源或等待房源审核通过',
    success: () => {
      uni.navigateTo({
        url: '/subPages/home/index'
      })
    },
    cancel: () => {}
  })
}
</script>

<style scoped>
.login-button {
  position: absolute;
  z-index: 9999;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
}
</style>
